package com.zyx.mybatis.mapper;

import com.zyx.mybatis.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper
{
	@Insert("insert into user_inf values (null, #{name}, #{password}, #{age})")
	int save(User user);

	@Delete("delete from user_inf where user_id = #{id}")
	int deleteById(Integer id);

	@Select("select user_id id, name, password, age from user_inf where user_id = #{id}")
	User findById(Integer id);

	@Update("update user_inf set name = #{name}, password = #{password}, age = #{age} where user_id = #{id}")
	int update(User user);

	@Select("select user_id id, name, password, age from user_inf where name like #{aa}")
	List<User> findByNameLike(String namePattern);
	@Select("select user_id id, name, password, age from user_inf where age > #{startAge}")
	List<User> findByAgeGreaterThan(int startAge);

	@Select("select user_id id, name, password, age from user_inf where age between #{startAge} and #{endAge}")
	List<User> findByAgeBetween(@Param("startAge") int startAge, @Param("endAge") int endAge);

	@Select("select user_id id, name, password, age from user_inf where password like #{passwordPattern}")
	List<User> findBySql(String passwordPattern);

	@Update("update user_inf set name = #{param1} where age between #{param2} and #{param3}")
	int updateNameByAge(String name, int startAge, int endAge);
}
